import Banner from "../Banner";
import Bullet from "../Bullet";
import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { DataManager } from "../Framework/Managers/DataManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
const { ccclass, property } = cc._decorator;

@ccclass
export default class FailPanel extends cc.Component {

    NameLabel: cc.Label = null;
    WeaponNameLabel: cc.Label = null;

    BlackMask: cc.Node = null;

    protected onLoad(): void {
        this.NameLabel = NodeUtil.GetComponent("NameLabel", this.node, cc.Label);
        this.WeaponNameLabel = NodeUtil.GetComponent("WeaponNameLabel", this.node, cc.Label);
        this.BlackMask = NodeUtil.GetNode("BlackMask", this.node);
    }

    Show(hitBullet: Bullet) {
        if (Banner.NeedShowMoreAd) {
            Banner.Instance.ShowVideoAd(() => { });
        }

        this.scheduleOnce(() => {
            Banner.Instance.ShowCustomAd();
        }, 1);

        DataManager.EXP += 500;
        cc.Tween.stopAllByTarget(this.BlackMask);
        this.BlackMask.opacity = 255;
        cc.tween(this.BlackMask).to(1, { opacity: 0 }).start();

        if (hitBullet) {
            this.NameLabel.string = `${hitBullet.playerData.Name}`;
            this.WeaponNameLabel.string = `${hitBullet.weapon.Name}`;
        }

        UIManager.Instance.ShowPanel(Constant.Panel.TreasureBox);
    }

    OnButtonClick(event: cc.Event) {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);

        switch (event.target.name) {
            case "EndButton":
                UIManager.Instance.ShowPanel(Constant.Panel.LoadingPanel, [`Start`]);
                break;
        }
    }
}
